﻿#ifndef ScopeGuard_h__2013_7_26__18_02
#define ScopeGuard_h__2013_7_26__18_02


#include "df_macro.h"

namespace df
{
	template<typename _FuncT>
	class ScopeGuard
	{
	public:
		inline explicit ScopeGuard(_FuncT onExitScope)
			: onExit_(onExitScope)
		{ }

		inline ~ScopeGuard()
		{
			onExit_();
		}

	private:
		_FuncT  onExit_;

		DF_DISABLE_COPY_ASSIGN(ScopeGuard);
	};


}

///超出作用域(return,抛异常或大括号结束)自动调用表达式:callBack
#define ON_SCOPE_EXIT(_callBack) auto DF_MIX_LINENAME(LAMBDA, __LINE__)=[&]()mutable _callBack;	\
	df::ScopeGuard<decltype(DF_MIX_LINENAME(LAMBDA, __LINE__))> DF_MIX_LINENAME(EXIT, __LINE__)(DF_MIX_LINENAME(LAMBDA, __LINE__))

#endif // ScopeGuard_h__2013_7_26__18_02
